<?php

namespace App\Services\Message;

use App\Libs\Commons\MyLogger;
use App\Libs\Commons\MyMessage;
use \Yunpian\Sdk\YunpianClient;

/**
 * 云片服务
 *
 * @example
 * @author mengsen
 * @since
 */
class YunpianService
{
    public static function send($param = [])
    {
        try {
            MyLogger::info('短信参数', $param);
            $client = YunpianClient::create(config('common.yunpian.sms.apikey'));            
            $result = $client->sms()->single_send($param);
            
            MyLogger::info('短信响应', ['msg' => $result->msg()]);
            if (!$result->isSucc()) {
                throw new \Exception($result->msg(), MyMessage::ERROR);
            }
            return $result->data();
        } catch (\Throwable $e) {
            MyLogger::info('短信响应', ['code' => $e->getCode(), 'msg' => $e->getMessage()]);
            throw new \Exception("发送失败", 0);
        }
    }
}
